#!/bin/bash

# set -ux

# 变量 前2个是namenode
nodes=(server160 server161 server162)
user=root

for node in ${nodes[@]}; do
  echo "启动  $node zookeeper"
  ssh $user@$node zkServer.sh start
  ssh $user@$node zkServer.sh status
done

echo "启动journalnode(所有节点)"
hdfs --workers --daemon start journalnode

echo "server160 格式化主节点namenode,然后启动"
hdfs namenode -format &&
  hdfs --daemon start namenode

echo "server161 在从节点 同步主节点namenode到备份namenode"
ssh root@server161 hdfs namenode -bootstrapStandby

echo "server160 在主节点namenode格式化zk"
hdfs zkfc -formatZK

echo "停止主节点namenode和所有节点的journalnode"
hdfs --workers --daemon stop journalnode &&
  hdfs --daemon stop namenode

echo '启动集群'
start-all.sh

echo "查看hadoop 进程"
ps -ef | grep hadoop

echo '查看各主节点状态hdfs/yarn'
hdfs haadmin -getAllServiceState &&
  yarn rmadmin -getAllServiceState

echo "查看jps"
jps

# echo '关闭集群'
# stop-all.sh

# ps -ef | grep hadoop
# ps -ef | grep hadoop | grep -v 'color' | awk '{print $2}' | xargs kill -9

# rm -rf /home/hadoop/{tmp,logs}/* && rm -rf /home/hadoop/hdfs/{journal,name,data}/*
# rm -rf /home/{zookeeper,hadoop}/logs/*
